package com.ruoyi.web.controller.rewards;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Rewards;
import com.ruoyi.system.service.IRewardsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2025-04-19
 */
@RestController
@RequestMapping("/system/rewards")
public class RewardsController extends BaseController
{
    @Autowired
    private IRewardsService rewardsService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:rewards:list')")
    @GetMapping("/list")
    public TableDataInfo list(Rewards rewards)
    {
        startPage();
        List<Rewards> list = rewardsService.selectRewardsList(rewards);
        return getDataTable(list);
    }
    @GetMapping("/mylist")
    public TableDataInfo list(Rewards rewards, Integer pageNum, Integer pageSize) {
        // 设定分页参数（页码、每页大小）
        PageHelper.startPage(pageNum, pageSize);
        List<Rewards> list = rewardsService.selectRewardsList(rewards);
        return getDataTable(list);
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:rewards:all')")
    @GetMapping("/all")
    public TableDataInfo listAll(Rewards rewards)
    {
        startPage();
        List<Rewards> list = rewardsService.selectRewardsLists(rewards);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:rewards:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Rewards rewards)
    {
        List<Rewards> list = rewardsService.selectRewardsList(rewards);
        ExcelUtil<Rewards> util = new ExcelUtil<Rewards>(Rewards.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rewards:query')")
    @GetMapping(value = "/{rewardsid}")
    public AjaxResult getInfo(@PathVariable("rewardsid") Long rewardsid)
    {
        return success(rewardsService.selectRewardsByRewardsid(rewardsid));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:rewards:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Rewards rewards)
    {
        rewards.setManager(SecurityUtils.getLoginUser().getUser().getNickName());
        return toAjax(rewardsService.insertRewards(rewards));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:rewards:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rewards rewards)
    {
        return toAjax(rewardsService.updateRewards(rewards));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:rewards:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rewardsids}")
    public AjaxResult remove(@PathVariable Long[] rewardsids)
    {
        return toAjax(rewardsService.deleteRewardsByRewardsids(rewardsids));
    }
}
